package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.domain.Category;
import com.itheima.domain.Dish;
import com.itheima.domain.Setmeal;
//import com.itheima.exception.DandSException;
import com.itheima.mapper.CategoryMapper;
import com.itheima.service.CategoryService;
import com.itheima.service.DishService;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>implements CategoryService {
        @Autowired
        private DishService dishService;
        @Autowired
        private SetmealService setmealService;
    @Override
    public void remove(Long id) {
        LambdaQueryWrapper<Dish> lqw= new LambdaQueryWrapper<>();
        lqw.eq(Dish::getCategoryId,id);
        int count = dishService.count(lqw);
        if (count>0){
            //抛异常
//            throw new DandSException("当前分类关联菜品不能删除");
        }

        LambdaQueryWrapper<Setmeal> qw= new LambdaQueryWrapper<>();
        qw.eq(Setmeal::getCategoryId,id);
        int count1 = setmealService.count(qw);
        if (count1>0){
            //抛异常
//            throw new DandSException("当前分类关联套餐不能删除");
        }
        super.removeById(id);
    }
}
